package weaver.interfaces.jjy.duss.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;


public class WeaHRydjxthAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        RecordSet rs2 = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用: WeaHRydjxthAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("查询主表SQL：" + "select * from " + tablename + " where requestid=" + requestid);
        rs.next();
        String mainid = Util.null2String(rs.getString("id"));//外键
        String WERKS = Util.null2String(rs.getString("WERKS"));//人事范围编码
        String GJAHR = Util.null2String(rs.getString("GJAHR"));//年度
        String MONAT = Util.null2String(rs.getString("MONAT"));//月度
        String BMBM = Util.null2String(rs.getString("BMBM"));//部门编码
        String STATE = "0";
        String message = "";
        if ("8004".equals(WERKS) || "8007".equals(WERKS) || "ZB01".equals(WERKS)) {
            //更新明细表
            String SQL = "select pernr,jbxygz,jbtcgz,bmgdsk1,zzskjtc,jljj  from " + tablename + "_dt1 where mainid='" + mainid + "'and  gjahr='" + GJAHR + "'and  monat='" + MONAT + "' and bmbm='" + BMBM + "'";
            rs2.execute(SQL);
            baseBean.writeLog(SQL);
            while (rs2.next()) {
                String PERNR = Util.null2String(rs2.getString("PERNR"));//人员编码
                String updateSQL1 = "update uf_jxxfmx set jbxygz='',jbtcgz='',bmgdsk1='', zzskjtc='',jljj='' where gjahr='" + GJAHR + "'and  monat='" + MONAT + "' and bmbm='" + BMBM + "' and pernr=" + PERNR + "";
                rs2.executeUpdate(updateSQL1);
                baseBean.writeLog("执行语句：" + updateSQL1);
            }
            //更新汇总表
            String updateSQL = "update uf_jxxfhz set bmsbjbxy='' ,bmsbjbtc= '', bmsbsk='',bmsbzzskj='',bmsbjl='',zt='"+STATE+"'  where gjahr='" + GJAHR + "' and monat='" + MONAT + "' and bmbm='" + BMBM + "'";
            rs.executeUpdate(updateSQL);
            baseBean.writeLog("调用SQL" + updateSQL);
            return Action.SUCCESS;
        } else {
            //更新明细表
            String SQL = "select pernr,jbxygz,jbtcgz,bmgdsk1,zzskjtc,jljj  from " + tablename + "_dt1 where mainid='" + mainid + "'and  gjahr='" + GJAHR + "'and  monat='" + MONAT + "' and werks='" + WERKS + "'";
            rs2.execute(SQL);
            baseBean.writeLog(SQL);
            while (rs2.next()) {
                String PERNR = Util.null2String(rs2.getString("PERNR"));//人员编码
                String updateSQL1 = "update uf_jxxfmx set jbxygz='',jbtcgz='',bmgdsk1='', zzskjtc='',jljj='' where gjahr='" + GJAHR + "'and  monat='" + MONAT + "' and BMBM='" + WERKS + "' and pernr=" + PERNR + "";
                rs2.executeUpdate(updateSQL1);
                baseBean.writeLog("执行语句：" + updateSQL1);
            }
            //更新汇总表
            String updateSQL = "update uf_jxxfhz set bmsbjbxy='' ,bmsbjbtc= '', bmsbsk='',bmsbzzskj='',bmsbjl='',zt='"+STATE+"'  where gjahr='" + GJAHR + "' and monat='" + MONAT + "' and werks='" + WERKS + "'";
            rs.executeUpdate(updateSQL);
            baseBean.writeLog("调用SQL" + updateSQL);
            return Action.SUCCESS;
        }
    }
}

